/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ImagePanel.java
 *
 * Created on Mar 2, 2011, 2:15:58 PM
 */

package imat;

import java.awt.Graphics;
import java.awt.Image;
import javax.swing.ImageIcon;

/**
 *
 * @author andlu
 */
public class ImagePanel extends javax.swing.JPanel {

    private static final String IMAGES_PREFIX = "images/";
    private Image image;
    private String name = "";

    /** Creates new form ImagePanel */
    public ImagePanel() {
        initComponents();
    }

    public ImagePanel(String img) {
        this(new ImageIcon(IMAGES_PREFIX+img).getImage());
        initComponents();
        name = img;
    }

    public ImagePanel(Image img) {
        initComponents();
        this.image = img;
        repaint();
    }

    public void setImage(String img) {
        setImage(new ImageIcon(IMAGES_PREFIX+img).getImage());
        name = img;
    }

    public void setImage(Image img) {
        this.image = img;
        repaint();
    }

    public String getImage() {
        return name;
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(image, 0, 0, null);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 187, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 89, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
